/*
 * @Description 
 * @Autor lzhiqiang
 * @Date 2023-03-21 16:40:00
 * @LastEditors lzhiqiang
 * @LastEditTime 2023-04-05 14:42:32
 */
#ifndef __HTTP_SESSION_H__
#define __HTTP_SESSION_H__

#include "stream/socket_stream.h"
#include "http.h"
#include "http_parser.h"

namespace johnsonli
{
namespace http
{
    /**
     * @brief HTTPSession封装
     */
    class HttpSession : public SocketStream {
    public:
        /// 智能指针类型定义
        typedef std::shared_ptr<HttpSession> ptr;

        /**
         * @brief 构造函数
         * @param[in] sock Socket类型
         * @param[in] owner 是否托管
         */
        HttpSession(Socket::ptr sock, bool owner = true);

        /**
         * @brief 接收HTTP请求
         */
        HttpRequest::ptr recvRequest();

        /**
         * @brief 发送HTTP响应
         * @param[in] rsp HTTP响应
         * @return >0 发送成功
         *         =0 对方关闭
         *         <0 Socket异常
         */
        int sendResponse(HttpResponse::ptr rsp);
    }; 
}
}

#endif